﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAO.BLL;
using System.Text;
using NHibernate.Criterion;
namespace Web.helper
{
    public static class HtmlSelect
    {
        public static string select_nav(this HtmlHelper helper)
        {
            B_Navigation b_nav = new B_Navigation();
            //先查询出所有的一级菜单
            List<Order> order = new List<Order>() { Order.Asc("sort_id") };
            var list_nav = b_nav.LoadAll(order,0);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"txt_parent_id\" name=\"txt_parent_id\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"一级菜单\">");
            sb.Append("<option data-subtext=\"一级菜单\" selected = \"true\">0</option>");
            sb.Append("</optgroup>");
            foreach (var nav in list_nav)
            {
                sb.Append("<optgroup label=" + nav.title + ">");
                sb.Append("<option data-subtext=" + nav.title + ">" + nav.id + "</option>"); //一级菜单放第一个
                //查询二级菜单
                var list_sub_nav = b_nav.LoadAll(order, nav.id);
                foreach (var sub_nav in list_sub_nav)
                {
                    sb.Append("<option data-subtext=" + sub_nav.title + ">" + sub_nav.id + "</option>"); //二级菜单
                }
                sb.Append("</optgroup>");
            }
            sb.Append("</select>");
            return sb.ToString();
        }
    }
}